package com.lza.phone.controller;



import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lza.phone.entity.User;
import com.lza.phone.service.UserService;
import com.lza.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李钊澳
 * @since 2021-09-05
 */

@RestController
public class UserController {
   @Autowired
    UserService userService;
  /* @PostMapping("/login")
    public Result login(@RequestBody User user){
       QueryWrapper<User> queryWrapper=new QueryWrapper<>();
       queryWrapper.eq("username", user.getUsername());
       User loginUser = userService.getOne(queryWrapper);
       if(loginUser==null){
           return Result.error().getMessage("用户名不存在或者密码错误");
       }else{
           if(loginUser.getPassword().equals(user.getPassword())){
               return Result.ok().getMessage("登陆成功");
           }else {
               return Result.error().getMessage("用户名不存在或者密码错误");
           }
       }

   }*/
  @CrossOrigin
    @ApiOperation("登陆接口")
    @ApiOperationSupport(author = "澳神弱爆")
    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpServletRequest httpServletRequest){
        return userService.login(user.getUsername(), user.getPassword(), httpServletRequest);
    }
    @ApiOperation("显示所有用户接口")
    @ApiOperationSupport(author = "澳神弱爆")
    @GetMapping("/showUser")
    public Result showUser(){
        List<User> users = userService.list();
        return Result.ok().getData("所有用户", users);
    }
    @CrossOrigin
    @ApiOperation("退出接口")
    @ApiOperationSupport(author = "澳神弱爆")
    @PostMapping("/logout")
    public Result logout(){
        return Result.ok().getMessage("登出处理成功");
    }


}

